$(function () {
    //进来先判断是否已经设置过   五险一金设置  POST 参数
    $.ajax({
        url:'http://jk.com/Admin/Index/setIns',
        type:'get',
        success:function(data){
            "use strict";
            if(data.code==1){
                let datas = data.data
                let person = datas.person
                let com = datas.com
                let shebao = datas.shebao
                let gjj = datas.gjj
                $('#canshu').find('[data-value=per_yanglao]').val(person.yanglao)
                $('#canshu').find('[data-value=per_yiliao]').val(person.yiliao)
                $('#canshu').find('[data-value=per_shiye]').val(person.shiye)
                $('#canshu').find('[data-value=per_shengyu]').val(person.shengyu)
                $('#canshu').find('[data-value=per_gongshang]').val(person.gongshang)
                $('#canshu').find('[data-value=per_gjj]').val(person.jin)

                $('#canshu').find('[data-value=com_yanglao]').val(com.yanglao)
                $('#canshu').find('[data-value=com_yiliao]').val(com.yiliao)
                $('#canshu').find('[data-value=com_shiye]').val(com.shiye)
                $('#canshu').find('[data-value=com_shengyu]').val(com.shengyu)
                $('#canshu').find('[data-value=com_gongshang]').val(com.gongshang)
                $('#canshu').find('[data-value=com_gjj]').val(com.jin)

                $('#canshu').find('[data-value=shebao_min]').val(shebao.low)
                $('#canshu').find('[data-value=shebao_max]').val(shebao.heigh)

                $('#canshu').find('[data-value=gjj_min]').val(gjj.low)
                $('#canshu').find('[data-value=gjj_max]').val(gjj.heigh)

                let c_shebao = datas.c_shebao
                let c_gjj = datas.c_gjj
                if(c_shebao){
                    $('.socialSecurityAuto').children('i').addClass('active')
                }else{
                    $('.socialSecurityAuto').children('i').removeClass('active')
                }

                if(c_gjj){
                    $('.publicAccumulatedFoundAuto').children('i').addClass('active')
                }else{
                    $('.publicAccumulatedFoundAuto').children('i').removeClass('active')
                }
            }
        }
    })
    $.ajax({
        url:'http://jk.com/Admin/Index/editAdmin',
        type:'get',
        success:function(data){
            "use strict";
            if(data.code==1){
                let datas = data.data
                $('#info').find('[data-value=people]').val(datas.name)
                $('#info').find('[data-value=phone]').val(datas.phone)
                $('#info').find('[data-value=pwd]').val(datas.password)
            }
        }
    })


        var btn1=$('.tabNavigationOne .editBtn')[0];
        EventUtil.addHandler(btn1,'click',function (event) {
            // console.log($('.topPart input'))
            if(btn1.innerHTML==="编辑"){
                $('#canshu').find('.BFBFBF_inputStyle').css('border','1px solid #ccc');
                $('#canshu').find('input').attr('readonly',false);
                btn1.innerHTML="完成";
            }
            else if(btn1.innerHTML==="完成"){

                let per_yanglao = $('#canshu').find('[data-value=per_yanglao]').val()
                let per_yiliao = $('#canshu').find('[data-value=per_yiliao]').val()
                let per_shiye = $('#canshu').find('[data-value=per_shiye]').val()
                let per_shengyu = $('#canshu').find('[data-value=per_shengyu]').val()
                let per_gongshang = $('#canshu').find('[data-value=per_gongshang]').val()
                let per_gjj = $('#canshu').find('[data-value=per_gjj]').val()
                let com_yanglao = $('#canshu').find('[data-value=com_yanglao]').val()
                let com_yiliao = $('#canshu').find('[data-value=com_yiliao]').val()
                let com_shiye = $('#canshu').find('[data-value=com_shiye]').val()
                let com_shengyu = $('#canshu').find('[data-value=com_shengyu]').val()
                let com_gongshang = $('#canshu').find('[data-value=com_gongshang]').val()
                let com_gjj = $('#canshu').find('[data-value=com_gjj]').val()
                let shebao_min = $('#canshu').find('[data-value=shebao_min]').val()
                let shebao_max = $('#canshu').find('[data-value=shebao_max]').val()
                let gjj_min = $('#canshu').find('[data-value=gjj_min]').val()
                let gjj_max = $('#canshu').find('[data-value=gjj_max]').val()

                console.log(per_yanglao,per_yiliao,per_shiye,per_shengyu,per_gongshang,per_gjj)
                console.log(com_yanglao,com_yiliao,com_shiye,com_shengyu,com_gongshang,com_gjj)
                console.log(shebao_min,shebao_max,gjj_min,gjj_max)
                if(!per_yanglao || !per_yiliao || !per_shiye || !per_shengyu || !per_gongshang || !per_gjj || !com_yanglao || !com_yiliao || !com_shiye || !com_shengyu || !com_gongshang || !com_gjj || !shebao_min || !shebao_max || !gjj_min || !gjj_max){
                    console.log(1)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    return
                }

                let o_person = {}
                let o_com = {}
                let o_shebao = {}
                let o_gjj = {}
                let datas = {}

                o_person.yanglao = per_yanglao
                o_person.yiliao = per_yiliao
                o_person.shiye = per_shiye
                o_person.shengyu = per_shengyu
                o_person.gongshang = per_gongshang
                o_person.jin = per_gjj

                o_com.yanglao = com_yanglao
                o_com.yiliao = com_yiliao
                o_com.shiye = com_shiye
                o_com.shengyu = com_shengyu
                o_com.gongshang = com_gongshang
                o_com.jin = com_gjj

                o_shebao.heigh = shebao_max
                o_shebao.low = shebao_min

                o_gjj.heigh = gjj_max
                o_gjj.low = gjj_min

                datas.person = o_person
                datas.com = o_com
                datas.shebao = o_shebao
                datas.gjj = o_gjj
                if($('.socialSecurityAuto').children('i').hasClass('active')){
                    datas.c_shebao = 1
                }else{
                    datas.c_shebao = 0
                }
                if($('.publicAccumulatedFoundAuto').children('i').hasClass('active')){
                    datas.c_gjj = 1
                }else{
                    datas.c_gjj = 0
                }

                $.ajax({
                    url:'http://jk.com/Admin/Index/setIns',
                    type:'post',
                    data:{
                        ins:datas
                    },
                    success:function(data){
                        "use strict";
                        if(data.code==1){
                            // console.log(data)
                            $('#canshu').find('.BFBFBF_inputStyle').css('border','1px solid transparent')
                            $('#canshu').find('input').attr('readonly',true);
                            btn1.innerHTML="编辑";
                        }
                    }
                })
            }

        });

        var btn2=$('.tabNavigationTwo .editBtn')[0];
        // console.log(btn2)
        EventUtil.addHandler(btn2,'click',function () {
        // console.log($('.topPart input'))
          if(btn2.innerHTML==="编辑"){
            // console.log(1)
            $('.tabNavigationTwo').siblings('ul').find('.BFBFBF_inputStyle').css('border','1px solid #ccc');
            // console.log($('.tabNavigationTwo').siblings('ul').find('.BFBFBF_inputStyle'))
            // $('.tabNavigationTwo').siblings('ul').find('BFBFBF_inputStyle').removeAttr('readonly');
            $('.tabNavigationTwo').siblings('ul').find('input').attr('readonly',false);
            btn2.innerHTML="完成";
        }
          else if(btn2.innerHTML==="完成"){

              let name = $('#info').find('[data-value=people]').val()
              let phone = $('#info').find('[data-value=phone]').val()
              let password = $('#info').find('[data-value=password]').val()

              if(!name || !phone || !password){
                  $('#yz_modal').addClass('active')
                  tipShow()
                  return
              }
              $.ajax({
                  url:'http://jk.com/Admin/Index/editAdmin',
                  type:'post',
                  data:{
                      name:name,
                      phone:name,
                      password:password
                  },
                  success:function(data){
                      "use strict";
                      if(data.code==1){
                          $('.tabNavigationTwo').siblings('ul').find('.BFBFBF_inputStyle').css('border','1px solid transparent')
                          $('.tabNavigationTwo').siblings('ul').find('input').attr('readonly',true);
                          btn2.innerHTML="编辑";
                      }
                  }
              })

          }
        // console.log(1)
       });

        var autoBtn1=$('.autoBtn')[0];
        var autoBtn2=$('.autoBtn')[1]
        EventUtil.addHandler(autoBtn1,'click',function () {
            if($(this).hasClass('active')){
                $(this).removeClass('active');
            }else if(!$(this).hasClass('active')){
                $(this).addClass('active');
            }
        })
        EventUtil.addHandler(autoBtn2,'click',function () {
            if($(this).hasClass('active')){
                $(this).removeClass('active');
            }else if(!$(this).hasClass('active')){
                $(this).addClass('active');
            }
        })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            // $('#yz_modal').removeClass('active')
            // $('#yz_modal').addClass('fadeOut')
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox)
        },2000)
    }
})